import os


os.environ["KICAD7_SYMBOL_DIR"] = "C:\\Program Files\\KiCad\\7.0\\share\\kicad\\symbols\\"
os.environ["KICAD7_3DMODEL_DIR"] = "C:\\Program Files\\KiCad\\7.0\\share\\kicad\\3dmodels\\"
os.environ["KICAD7_3RD_PARTY"] = "C:\\Program Files\\KiCad\\7.0\\share\\kicad\\3rdparty\\"
os.environ["KICAD7_FOOTPRINT_DIR"] = "C:\\Program Files\\KiCad\\7.0\\share\\kicad\\footprints\\"
os.environ["KICAD7_TEMPLATE_DIR"] = "C:\\Program Files\\KiCad\\7.0\\share\\kicad\\template\\"
os.environ["KICAD_USER_TEMPLATE_DIR"] = "C:\\Program Files\\KiCad\\7.0\\share\\kicad\\template\\"
os.environ["KICAD6_SYMBOL_DIR"] = "C:\\Program Files\\KiCad\\6.0\\share\\kicad\\symbols\\"
os.environ["KICAD6_3DMODEL_DIR"] = "C:\\Program Files\\KiCad\\6.0\\share\\kicad\\3dmodels\\"
os.environ["KICAD6_3RD_PARTY"] = "C:\\Program Files\\KiCad\\6.0\\share\\kicad\\3rdparty\\"
os.environ["KICAD6_FOOTPRINT_DIR"] = "C:\\Program Files\\KiCad\\6.0\\share\\kicad\\footprints\\"
os.environ["KICAD6_TEMPLATE_DIR"] = "C:\\Program Files\\KiCad\\6.0\\share\\kicad\\template\\"
os.environ["KICAD_USER_TEMPLATE_DIR"] = "C:/Program Files/KiCad/7.0/share/kicad/template/"
os.environ["KICAD_SYMBOL_DIR"] = "C:\\Program Files\\KiCad\\share\\kicad\\library\\"
os.environ["KICAD_3DMODEL_DIR"] = "C:\\Program Files\\KiCad\\7.0\\share\\kicad\\3dmodels\\"
os.environ["KICAD_3RD_PARTY"] = "C:\\Program Files\\KiCad\\7.0\\share\\kicad\\3rdparty\\"
os.environ["KICAD_FOOTPRINT_DIR"] = "C:\\Program Files\\KiCad\\share\\kicad\\modules\\"
os.environ["KICAD_TEMPLATE_DIR"] = "C:\\Program Files\\KiCad\\share\\kicad\\template\\"
os.environ["KICAD_USER_TEMPLATE_DIR"] = "C:\\Program Files\\KiCad\\7.0\\share\\kicad\\template\\"
from skidl import *



def gen_node4Env():
    set_default_tool(KICAD)
    q = Part("Device", "Q_PNP_CBE", dest=TEMPLATE)
    r = Part("Device", "R", dest=TEMPLATE)

    # Create nets.
    gnd, vcc = Net("GND"), Net("VCC")
    a, b, a_and_b = Net("A"), Net("B"), Net("A_AND_B")

    # Instantiate parts.
    gndt = Part("power", "GND")             # Ground terminal.
    vcct = Part("power", "VCC")             # Power terminal.
    q1, q2 = q(2)                           # Two transistors.
    r1, r2, r3, r4, r5 = r(5, value="10K")  # Five 10K resistors.

    # Make connections between parts.
    a & r1 & q1["B C"] & r4 & q2["B C"] & a_and_b & r5 & gnd
    b & r2 & q1["B"]
    q1["C"] & r3 & gnd
    vcc += q1["E"], q2["E"], vcct
    gnd += gndt
    with Group("B"):
        r = Part('Device', 'R')
        r6, r7 = r(2,value = "10K")
        r6 & r7 & r6
        with Group("C"):
            r = Part('Device', 'R')
            r8, r9 = r(2,value = "10K")
            r8 & r9 & r8
    return generate_node()
    #generate_svg()

if __name__ == "__main__":
    gen_node4Env()